/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.network.topo.subnetwork;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.geom.Ellipse2D;
import java.io.IOException;

import twaver.ShapeSubNetwork;
import twaver.TDataBox;
import twaver.TWaverConst;
import twaver.network.TNetwork;
import twaver.network.background.TextureBackground;
import demo.DemoPane;


public class SubNetworkDemo extends DemoPane {
	
	public static class CustomBackground extends TextureBackground{
		public CustomBackground(){
			super("/demo/resource/images/texture.jpg");
		}
        public void paint(Graphics g, double zoom, Rectangle viewportRect) {
            super.paint(g, zoom, viewportRect);
            g.setColor(Color.red);
            g.setFont(new Font("Dialog", Font.ITALIC, 20));
            g.drawString("Let's double click to go back.", 10, 50);
        }
	}
	
    TDataBox box = new TDataBox();
    TNetwork network = new TNetwork(box);

    public SubNetworkDemo() {
        this.add(network, BorderLayout.CENTER);

        network.setToolbarByName(TWaverConst.DEFAULT_TOOLBAR);
        network.setImageBackground("/demo/resource/images/europe.gif");

        //create subnetwork by API.
        Ellipse2D ellipse = new Ellipse2D.Float(100, 100, 200, 100);
        ShapeSubNetwork subnetwork = new ShapeSubNetwork(ellipse);
        subnetwork.setLocation(100, 100);
        subnetwork.setName("Double click me to drill down.");
        subnetwork.putLabelPosition(TWaverConst.POSITION_TOP);
        subnetwork.putLabelFont(new Font("Forte", Font.BOLD, 20));
        subnetwork.putLabelColor(Color.orange.darker());
        subnetwork.putCustomDrawOutlineColor(Color.orange.darker());
        subnetwork.setImageBackground("/demo/resource/images/usa.gif");
        box.addElement(subnetwork);
        //load subnetwork from XML.
        try {
            box.parse("/demo/network/topo/subnetwork/usa.xml", subnetwork);
            ShapeSubNetwork child = (ShapeSubNetwork) subnetwork.getChildren().get(0);
            child.setName("<html><center>Click me to drill down.<br>" +
                          "Or click blank area to drill up.</center></html>");
            child.putLabelFont(new Font("Arial", Font.BOLD, 20));
            child.putLabelColor(Color.white);
            child.putLabelPosition(TWaverConst.POSITION_CENTER);
            child.putLabelBorder(true);
            child.putCustomDrawOutlineColor(Color.magenta.darker());
            child.setBackground(new CustomBackground());
            box.parse("/demo/network/topo/subnetwork/group.xml", child);
        }
        catch (IOException ex) {
            ex.printStackTrace();
        }
        
    }

}